﻿/*************************************************************************
 * 
 * Filename :newslist
 * 
 * steven hu   2010/3/10 15:14:33
 *  
 * http://www.cnblogs.com/huxj
 *   
 * 
 * Change History:
 * 
 * 
**************************************************************************/



using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hxj.Data;
using RicciWebsite.Model;
using System.Data;

namespace RicciWebsite.admin.news
{
    public partial class newslist : RicciWebsite.Pages.AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData();
            }
        }

        protected string getStatus(object status)
        {
            int statusint = Hxj.Common.ConvertHelper.ToInt32(status, 0);
            switch (statusint)
            {
                case 0:
                    return "未发布";
                case 2:
                    return "置顶";
                default:
                    return "已发布";
            }
        }



        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pager_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }


        /// <summary>
        /// 数据
        /// </summary>
        private void bindData()
        {
            WhereClip where = new WhereClip();
            if (!string.IsNullOrEmpty(txtTitle.Value.Trim()))
            {
                where = where.And(data_news._.ntitle.Contain(txtTitle.Value.Trim()));
            }

            if (!string.IsNullOrEmpty(txtStart.Value.Trim()))
            {
                where = where.And(data_news._.subtime >= txtStart.Value);
            }

            if (!string.IsNullOrEmpty(txtEnd.Value.Trim()))
            {
                where = where.And(data_news._.subtime <= txtEnd.Value);
            }

            if (ddlstate.SelectedIndex > 0)
            {
                where = where.And(data_news._.status == ddlstate.Value);
            }

            FromSection<data_news> from = RicciDatabase.Default.From<data_news>().Where(where).OrderBy(data_news._.subtime.Desc);

            pager.RecordCount = from.Count();

            using (IDataReader reader = from.Page(pager.PageSize, pager.CurrentPageIndex).ToDataReader())
            {
                rptnewslist.DataSource = reader;
                rptnewslist.DataBind();
            }

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            pager.CurrentPageIndex = 1;
            bindData();
        }
    }
}
